import React from 'react';
import { inject, observer } from 'mobx-react';
import * as mobx from 'mobx';
import base from './../../../util/base';
import startsWith from "lodash/startsWith";
import isEmpty from "lodash/isEmpty";
import FormSignInput from './../../../asyncComps/FormSignInput'
import './index.less';

import { getAntd, getEcCom, getLabel, getComsMobx } from '../../../util/convert';

@inject('freeWflowSimpleStore')
@observer
export default class Main extends React.Component {

    render() {
        const { markInfo = {} } = base.globalStore;
        const { isHideInput } = markInfo;
        const {  WeaRightMenu} = getEcCom();
        let remark = window.CK_REF && window.CK_REF.remark && window.CK_REF.remark.getEditor().getData() ? window.CK_REF.remark.getEditor().getData() : '';
        if (window.CK_REF && window.CK_REF.freeWorkflowSimple && window.CK_REF.freeWorkflowSimple.getEditor().getData())
            remark = window.CK_REF.freeWorkflowSimple.getEditor().getData(); 
        return (
            <div className="wf-free-flow-simple">
                <WeaRightMenu {...this.props.getMoreBtns()}>
                    <div className="wf-free-flow-simple-content">
                        {isHideInput == 0 && <FormSignInput remark={remark}  visible={this.props.visible} src={"freeWorkflowSimple"} isPropOpenSignInput={true} />}
                        {this.getForm()}
                    </div>
                </WeaRightMenu>
            </div>
        )
    }

    getForm = () => {
        const { WeaTools, WeaFormItem, WeaSearchGroup } = getEcCom();
        const { WeaSwitch } = getComsMobx();
        const { freeWflowSimpleStore } = this.props;
        const { form, conditioninfo } = freeWflowSimpleStore;
        let group = [];
        let that = this;
        /**常用查询条件 */
        if (!form) return;
        const formParams = form.getFormParams();
        let condition = mobx.toJS(conditioninfo);

        form.isFormInit && condition.map(c => {
            let items = [];
            c.items.map(field => {
                let col = 1;
                if (field.conditionType.toUpperCase() == WeaTools.types.CASCADER) col = 1;
                items.push({
                    com: (<WeaFormItem
                        label={`${field.label}`}
                        labelCol={{ span: `${field.labelcol}`, offset: 5 }}
                        error={form.getError(field)}
                        tipPosition="bottom"
                        wrapperCol={{ span: `${field.fieldcol}`, offset: 1 }}>
                        <WeaSwitch fieldConfig={field} form={form} onChange={this.onChange} onBlur={this.onBlur} />
                    </WeaFormItem>),
                    col: col,
                    hide: form.isHide(field, (keys, allParams) => {
                        return false;
                    })
                })
            });
            group.push(<WeaSearchGroup needTigger={true} title={c.title} showGroup={c.defaultshow} items={items} />)
        });
        return <div className='wf-free-flow-simple-form'>{group}</div>;
    }

    onChange = (v, c) => {
        if (v["isToNewAddSign"]) {
            const { changeForm } = this.props.freeWflowSimpleStore;
            changeForm(c.value)
        }
    }

    onBlur = (v, c) => {
        // console.log("v,c", v, c)
    }

    doSubmit = () => {
        const { doSubmit } = this.props.freeWflowSimpleStore;
        doSubmit();
    }
}
